package com.ruoyi.violation.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.construction.domain.ConstructionSite;
import com.ruoyi.construction.mapper.ConstructionSiteMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.violation.mapper.ConstructionSiteCheckReportMapper;
import com.ruoyi.violation.domain.ConstructionSiteCheckReport;
import com.ruoyi.violation.service.IConstructionSiteCheckReportService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 项目巡查记录Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-12-14
 */
@Service
public class ConstructionSiteCheckReportServiceImpl implements IConstructionSiteCheckReportService 
{
    @Autowired
    private ConstructionSiteCheckReportMapper constructionSiteCheckReportMapper;
    @Autowired
    private ConstructionSiteMapper constructionSiteMapper;

    /**
     * 查询项目巡查记录
     * 
     * @param id 项目巡查记录主键
     * @return 项目巡查记录
     */
    @Override
    public ConstructionSiteCheckReport selectConstructionSiteCheckReportById(Long id)
    {
        return constructionSiteCheckReportMapper.selectConstructionSiteCheckReportById(id);
    }

    /**
     * 查询项目巡查记录列表
     * 
     * @param constructionSiteCheckReport 项目巡查记录
     * @return 项目巡查记录
     */
    @Override
    public List<ConstructionSiteCheckReport> selectConstructionSiteCheckReportList(ConstructionSiteCheckReport constructionSiteCheckReport)
    {
        return constructionSiteCheckReportMapper.selectConstructionSiteCheckReportList(constructionSiteCheckReport);
    }

    /**
     * 新增项目巡查记录
     * 
     * @param constructionSiteCheckReport 项目巡查记录
     * @return 结果
     */
    @Override
    public int insertConstructionSiteCheckReport(ConstructionSiteCheckReport constructionSiteCheckReport)
    {
        constructionSiteCheckReport.setCreateTime(DateUtils.getNowDate());
        return constructionSiteCheckReportMapper.insertConstructionSiteCheckReport(constructionSiteCheckReport);
    }

    /**
     * 修改项目巡查记录
     * 
     * @param constructionSiteCheckReport 项目巡查记录
     * @return 结果
     */
    @Override
    public int updateConstructionSiteCheckReport(ConstructionSiteCheckReport constructionSiteCheckReport)
    {
        constructionSiteCheckReport.setUpdateTime(DateUtils.getNowDate());
        return constructionSiteCheckReportMapper.updateConstructionSiteCheckReport(constructionSiteCheckReport);
    }

    /**
     * 批量删除项目巡查记录
     * 
     * @param ids 需要删除的项目巡查记录主键
     * @return 结果
     */
    @Override
    public int deleteConstructionSiteCheckReportByIds(Long[] ids)
    {
        return constructionSiteCheckReportMapper.deleteConstructionSiteCheckReportByIds(ids);
    }

    /**
     * 删除项目巡查记录信息
     * 
     * @param id 项目巡查记录主键
     * @return 结果
     */
    @Override
    public int deleteConstructionSiteCheckReportById(Long id)
    {
        return constructionSiteCheckReportMapper.deleteConstructionSiteCheckReportById(id);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int addJoin(ConstructionSiteCheckReport constructionSiteCheckReport) {
        Long isImportFocus = constructionSiteCheckReport.getIsImportFocus();
        Long isTop = constructionSiteCheckReport.getIsTop();
        Long isProjectCompleted = constructionSiteCheckReport.getIsProjectCompleted();
        ConstructionSite constructionSite = constructionSiteMapper.selectConstructionSiteById(constructionSiteCheckReport.getConstructionSiteId()+"");
        constructionSite.setIsTop(isTop);
        constructionSite.setIsImportFocus(isImportFocus);
        constructionSite.setIsProjectCompleted(isProjectCompleted);
        constructionSite.setCreateTime(DateUtils.getNowDate());
        constructionSiteCheckReport.setCreateTime(DateUtils.getNowDate());
        constructionSiteCheckReport.setCheckTime(DateUtils.getNowDate());
        int i = constructionSiteMapper.updateConstructionSite(constructionSite);
        if(i>0){
           i =  constructionSiteCheckReportMapper.insertConstructionSiteCheckReport(constructionSiteCheckReport);
        }

        return i;
    }
}
